home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 5 / Amiga Tools 5.iso / tools / developer-tools / aros / source / exec / tasks / src / findtask.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-07-16  |  2.1 KB  |  98 lines

  1. /*
  2.     $Id: findtask.c 1.1 1995/12/17 21:37:10 digulla Exp digulla $
  3.     $Log: findtask.c $
  4.  * Revision 1.1  1995/12/17  21:37:10  digulla
  5.  * Initial revision
  6.  *
  7.     Desc:
  8.     Lang: english
  9. */
  10. #include "exec_intern.h"
  11.  
  12. /*****************************************************************************
  13.  
  14.     NAME */
  15.     #include <clib/exec_protos.h>
  16.  
  17.     __AROS_LH1(struct Task *, FindTask,
  18.  
  19. /*  SYNOPSIS */
  20.     __AROS_LA(UBYTE *, name, A1),
  21.  
  22. /*  LOCATION */
  23.     struct ExecBase *, SysBase, 49, Exec)
  24.  
  25. /*  FUNCTION
  26.     Find a task with a given name or get the address of the current task.
  27.     Finding the address of the current task is a very quick function
  28.     call, but finding a special task is a very CPU intensive instruction.
  29.     Note that generally a task may already be gone when this function
  30.     returns.
  31.  
  32.     INPUTS
  33.     name - Pointer to name or NULL for current task.
  34.  
  35.     RESULT
  36.     Address of task structure found.
  37.  
  38.     NOTES
  39.  
  40.     EXAMPLE
  41.  
  42.     BUGS
  43.  
  44.     SEE ALSO
  45.  
  46.     INTERNALS
  47.  
  48.     HISTORY
  49.     29-10-95    digulla automatically created from
  50.                 exec_lib.fd and clib/exec_protos.h
  51.     17-12-95    digulla Incorporated code by Matthias Fleischner
  52.  
  53. *****************************************************************************/
  54. {
  55.     __AROS_FUNC_INIT
  56.     struct Task *ret;
  57.  
  58.     /* Quick return for a quick argument */
  59.     if(name==NULL)
  60.     return SysBase->ThisTask;
  61.  
  62.     /* Always protect task lists with a Disable(). */
  63.     Disable();
  64.  
  65.     /* First look into the ready list. */
  66.     ret=(struct Task *)FindName(&SysBase->TaskReady,name);
  67.     if(ret==NULL)
  68.     {
  69.     /* Then into the waiting list. */
  70.     ret=(struct Task *)FindName(&SysBase->TaskWait,name);
  71.     if(ret==NULL)
  72.     {
  73.         /*
  74.         Finally test the current task. Note that generally
  75.         you know the name of your own task - so it is close
  76.         to nonsense to look for it this way.
  77.         */
  78.         char *s1=SysBase->ThisTask->tc_Node.ln_Name;
  79.         char *s2=name;
  80.  
  81.         /* Check as long as the names are identical. */
  82.         while(*s1++==*s2)
  83.         /* Terminator found? */
  84.         if(!*s2++)
  85.         {
  86.             /* Got it. */
  87.             ret=SysBase->ThisTask;
  88.             break;
  89.         }
  90.     }
  91.     }
  92.  
  93.     /* Return whatever I found. */
  94.     Enable();
  95.     return ret;
  96.     __AROS_FUNC_EXIT
  97. } /* FindTask */
  98.